Imports System.IO

Imports System.Drawing

Imports System.Runtime.InteropServices

''' <summary>
''' Controls retrieving the associated gif file from the icons sub folder.
''' </summary>
''' <remarks>
''' This can be expanded to handle most file types by simply placing a gif file
''' in the icons folder with the file extension as the file name. (ie. ext.gif)
''' ITLackey - 10.29.07
''' </remarks>
Public Class IconController


    Private imageDirectory As String = IO.Path.Combine(My.Application.Info.DirectoryPath, "Icons")

    Private Shared defaultIcon As String = IO.Path.Combine(My.Application.Info.DirectoryPath, "Icons\missing.gif")

    Public Function GetImageByExt(ByVal ext As String) As Image
        'todo caching?

        Dim fileName As String = ""

        fileName = Path.Combine(imageDirectory, "File.gif")

        Try
            If ext = "folder" Then

                fileName = Path.Combine(imageDirectory, "folder.gif")

            Else

                If ext <> "" AndAlso File.Exists(Path.Combine(imageDirectory, ext & ".gif")) Then

                    fileName = Path.Combine(imageDirectory, ext & ".gif")

                Else

                    fileName = defaultIcon

                End If
            End If

        Catch exc As Exception
            'todo handle

            fileName = defaultIcon

        End Try

        Return New Bitmap(fileName)

    End Function

End Class
